library(happign)
#> Warning in CPL_gdal_init(): GDAL Message 1: Unable to find driver DODS to
#> unload from GDAL_SKIP environment variable.
#> Warning in CPL_gdal_init(): GDAL Message 1: Unable to find driver DODS to
#> unload from GDAL_SKIP environment variable.
#> Please make sure you have an internet connection.
#> Use happign::get_last_news() to display latest geoservice news.
library(tmap); tmap_mode("view")
#> tmap mode set to interactive viewingPresentation
APIs carto were developed to automatically retrieve certain spatial
information required in administrative forms (e.g. for a building permit
application, the identifier of the cadastral parcel can often be
obtained directly from the address). The main advantage of these APIs is
that they can be queried without spatial data. To do this with
get_wfs, you would have to use an ECQL query with the
ecql_filter argument which can be tricky.
happign implements APIs carto through
get_apicarto_* functions
API carto cadastre
Documentation : https://apicarto.ign.fr/api/doc/cadastre
The API carto cadastre provides the following information : * the
boundaries of a town (type = "commune") * the parcel
sections or divisions (type = "section" or
type = "division") * the cadastral parcels
(type = "cadastre") * information on non-vectorized parcels
(type = "localisant")
At least three parameters must be set : * x : An
indication about the location. Could be a shape, an insee code or a
departement code * type : What service do you want to use?
(see above) * source : The data source "PCI"
for “Parcellaire Express” or "BDP" for “BD Parcellaire”.
The BD Parcellaire product is a historical product that is no longer
updated. It is therefore strongly recommended to use the Parcellaire
Express product which is updated every six months.
All other parameters are used to refine the query.
Usage
We’ll start with a simple example : retrieve borders of multiple
town. Because get_apicaro_cadastre is a vectorized
function, it’s possible to set multiple insee code. If you do not know
insee codes, you can consult existing codes from the internal dataframe
cog_2022.
# all town starting with plou
plou_insee_code <- cog_2022[startsWith(cog_2022$LIBELLE, "Plou"), "COM"]
plou_borders <- get_apicarto_cadastre(plou_insee_code, type = "commune")
# result
tm_shape(plou_borders)+
tm_borders(col = "black")Another common case consists in recovering the geometry of the parcels from a “cadastral matrix extract”. The latter lists for each owner all his built and unbuilt properties owned in a commune. It is a private information and to obtain one it is necessary to ask for an extract top the Center of the Land taxes. In this example a false simplified cadastral matrix is used.
cad_mat <- data.frame(CODE_DEP = rep("29", 10),
CODE_COM = rep("158", 10),
SECTION = rep(c("AX", "AV"), each = 5),
N_PARC = c("0001","0002","0003","0004","0005",
"0116","0117","0118","0119","0120"))
parcels <- get_apicarto_cadastre(paste0(cad_mat$CODE_DEP, cad_mat$CODE_COM),
section = cad_mat$SECTION,
numero = cad_mat$N_PARC)
#> Features downloaded : 1
#> Features downloaded : 1
#> Features downloaded : 1
#> Features downloaded : 1
#> Features downloaded : 0
#> Features downloaded : 1
#> Features downloaded : 1
#> Features downloaded : 1
#> Features downloaded : 1
#> Features downloaded : 1
tm_shape(parcels)+
tm_borders(col = "black")